import { createStore } from "vuex";
import createPersistedstate from 'vuex-persistedstate'
export default createStore({
  state: {
    balance:0,
    address:'',
    // 我的消费
    totalamount: 0,
    // 我的收款
    shopmoney: 0,
    // 当前算力
    totalStakeAmount: 0,
    // 待提收益
    releaseAmount: 0,
    // 累计总额
    totalPay: 0,
    // 消费矿池余额
    // 消费挖矿页面
    totalPoint: 0,
    calDayReleaseRate: 0,
    totalPayAmount: 0,
    widthdrawnAmount: 0,
    refReward: 0,
  },
  mutations: {
    BALANCE(state, payload) {
      state.balance = payload;
    },
    changeAddress(state, payload) {
      state.address = payload;
    },
    changeCalDayReleaseRate(state, payload) {
      state.calDayReleaseRate = payload;
    },
    changeTotalPayAmount(state, payload) {
      state.totalPayAmount = payload;
    },
    changeWidthdrawnAmount(state, payload) {
      state.widthdrawnAmount = payload;
    },
    changeRefReward(state, payload) {
      state.refReward = payload;
    },
    changeTotalamount(state, payload) {
      state.totalamount = payload;
    },
    changeShopmoney(state, payload) {
      state.shopmoney = payload;
    },
    changeTotalStakeAmount(state, payload) {
      state.totalStakeAmount = payload;
    },
    changeReleaseAmount(state, payload) {
      state.releaseAmount = payload;
    },
    changeTotalPay(state, payload) {
      state.totalPay = payload;
    },
    ADDRESS(state, payload) {
      state.address = payload;
    },
  },
  actions: {},
  plugins: [
    // 持久化插件
    createPersistedstate({
      storage: window.localStorage,
      reducer(val) {
        return {
          // 我的消费
          totalamount: val.totalamount,
          // 我的收款
          shopmoney: val.shopmoney,
          // 当前我的算力
          totalStakeAmount: val.totalStakeAmount,
          // 待提收益
          releaseAmount: val.releaseAmount,
          // 累计总额
          totalPay: val.totalPay,
          // 消费矿池余额
          totalPoint: val.totalPoint,
          calDayReleaseRate: val.calDayReleaseRate,
          totalPayAmount: val.totalPayAmount,
          widthdrawnAmount: val.widthdrawnAmount,
        };
      },
    }),
  ],
  modules: {},
});